﻿using System;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Function.Statistics {
    public class SumNode : FuncNode {
        
        public SumNode()
            : base() {
            base.Value = "sum";
        }

        public override object Evaluate()
        {
            if (Parameters.Count < 1)
            {
                throw new ArgumentException(
                    "usage: sum(number1, number2, number3, number4, ...)");
            }

            double sum = 0;
            foreach (Node c in Parameters) {
                sum += Convert.ToDouble(c.Value);
            }

            return sum.ToString();
        }
    }
}
